﻿using Common;
using Result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Api
{
    /// <summary>
    /// High-level wrapper for {@link Result} instance.
    /// </summary>
    public sealed class SpeechResult: ISpeechResult
    {
        private IResult result;
        private Lattice lattice;

        /**
        /// Constructs recognition result based on {@link Result} object.
         *
        /// @param scorer confidence scorer
        /// @param result recognition result returned by {@link Recognizer}
         */
        public SpeechResult(IResult result) 
        {
            this.result = result;
            lattice = new Lattice(result);
            new LatticeOptimizer(lattice).optimize();
        }

        /**
        /// Returns {@link List} of words of the recognition result.
        /// Within the list words are ordered by time frame.
         *
        /// @return words that form the result
         */
        public List<IWordResult> getWords() 
        {
            return result.getTimedBestResult(true);
        }

        /**
        /// Returns string representation of the result.
         */
        public String getHypothesis() 
        {
	        return result.getBestResultNoFiller();
        }

        /**
        /// Return N best hypothesis.
         *
        /// @param  n number of hypothesis to return
        /// @return   {@link Collection} of several best hypothesis
         */
        public List<String> getNbest(int n) 
        {
            return new Nbest(lattice).getNbest(n);
        }

        /**
        /// Returns lattice for the recognition result.
         *
        /// @return lattice object
         */
        public Lattice getLattice() {
            return lattice;
        }
    
        /**
        /// Return Result object of current SpeechResult
        /// 
        /// @return Result object stored in this.result
         */
        public IResult getResult() {
    	    return result;
        }

    }
}
